package com.lemon.smartsafety.ui.activity.safe.data.contract;

import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.BundleKey;
import com.lemon.smartsafetynew.ui.activity.base.BaseSearchFragmentActivity;
import com.lemon.smartsafety.ui.fragment.safe.contract.KeepContractUnitListFragment;
import com.lemon.smartsafety.utils.common.StringUtils;

/**
 * Created by Cooliean on 16/3/31.
 */
public class KeepContractUnitListActivity extends BaseSearchFragmentActivity {
    private String mOldValue = null;


    private KeepContractUnitListFragment mFragment;


    private String sTypeId = "1";

    @Override
    protected void getBundleArgs() {
        super.getBundleArgs();
        if (getIntent().getExtras() != null) {
            mOldValue = getIntent().getStringExtra(BundleKey.OLD_SELECT_VALUE);
            sTypeId = getIntent().getStringExtra(BundleKey.TYPE_ID);
        }
        sTypeId = StringUtils.nullValue(sTypeId, "1");
    }


    @Override
    public Fragment getFragment() {
        return getFragment(null);
    }


    public Fragment getFragment(String text) {
        Bundle bundle = new Bundle();
        if (null != mOldValue) {
            bundle.putString(BundleKey.OLD_SELECT_VALUE, mOldValue);
        }
        if (null != text) {
            bundle.putString(BundleKey.KEY_WORD, text);
        }
        bundle.putString(BundleKey.TYPE_ID, sTypeId);
        mFragment = KeepContractUnitListFragment.newInstance();
        mFragment.setArguments(bundle);
        return mFragment;
    }

    @Override
    protected void initViews() {
        super.initViews();
        if (StringUtils.nullValue(sTypeId, "1").equals("2")) {
            setBarTitle(R.string.wuye_unit_prop_unit_list);
        }
    }

    @Override
    public boolean onQueryTextSubmit(String queryText) {
        replaceFragment(getFragment(queryText));
        return super.onQueryTextSubmit(queryText);
    }


    @Override
    public int getSearchHintRes() {
        return R.string.search_common_hit;
    }

    @Override
    protected void initTitle() {
        setBarTitle(R.string.keep_contract_prop_unit_list);
    }
}
